package org.paic.d;

import java.util.Properties;

import javax.sql.DataSource;

import org.paic.util.PropHelper;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class Ds {
    private static final String CONF_FILE = "/config/datasource.properties";

    private static Object lock = new Object();
    private static HikariDataSource ds;

    public static DataSource getInstance() {
        if (ds != null)
            return ds;

        synchronized (lock) {
            if (ds == null) {
                Properties props = PropHelper.loadProperties(CONF_FILE);
                HikariConfig config = new HikariConfig(props);
                ds = new HikariDataSource(config);
            }
        }
        return ds;
    }

    public void close() {
        if (ds != null)
            ds.close();
    }

}
